package threadcoreknowledge.stopthreads.scy1;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RightWayStopThreadWithoutSleep implements Runnable {

    @Override
    public void run() {
        long start = System.currentTimeMillis();
        int num = 0;
        while (
//                !Thread.currentThread().isInterrupted() &&
                        num <= Integer.MAX_VALUE / 2) {
            if (num % 10000 == 0) {
                System.out.println(num + "是10000的倍数");
            }
            num++;
        }
        long end = System.currentTimeMillis();
        System.out.println("任务运行结束了,共耗时:"+(end - start ) + "毫秒");
    }

    public static void main(String[] args) throws InterruptedException {


// 线程法
        Runnable runnable =  new RightWayStopThreadWithoutSleep();
        Thread thread = new Thread(runnable);
//        thread.start();
//        Thread.sleep(2*1000);
//        thread.interrupt();
//        thread.stop();


        // 线程池法
        ExecutorService threadPool = Executors.newFixedThreadPool(1);
        threadPool.execute(runnable);
        threadPool.shutdown();

    }
}
